package logic

import (
	"context"

	"mall/service/mqueue/common/types"
	"mall/service/mqueue/job/internal/svc"

	"github.com/hibiken/asynq"
)

type CronJob struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCronJob(ctx context.Context, svcCtx *svc.ServiceContext) *CronJob {
	return &CronJob{
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// register tasks
func (l *CronJob) RegisterJobProcessors() *asynq.ServeMux {
	// mux maps a type to a processor
	mux := asynq.NewServeMux()

	//scheduler job
	mux.Handle(types.ScheduleSettleRecord, NewSettleRecordProcessor(l.svcCtx))
	mux.Handle(types.ScheduleScanAttachmentLog, NewScanAttachmentLogProcessor(l.svcCtx))
	mux.Handle(types.SchedulePublishKbEntry, NewPublishKbEntryProcessor(l.svcCtx))
	mux.Handle(types.ScheduleScanPromotionActivity, NewScanPromotionActivityProcessor(l.svcCtx))
	mux.Handle(types.ScheduleScanPromotionCoupon, NewScanPromotionCouponProcessor(l.svcCtx))
	mux.Handle(types.SchedulePublishPost, NewPublishPostProcessor(l.svcCtx))
	mux.Handle(types.ScheduleScanUpdatedGorseCache, NewScanUpdatedGorseCacheProcessor(l.svcCtx))
	mux.Handle(types.ScheduleScanAttachmentLogDelete, NewScanAttachmentLogDeletedProcessor(l.svcCtx))

	// defer job
	mux.Handle(types.DeferedCloseOrder, NewDeferedCloseOrderProcessor(l.svcCtx))
	mux.Handle(types.DeferedStockSubtractRevert, NewDeferedStockSubtractRevertProcessor(l.svcCtx))

	mux.Handle(types.PeriodicityClearIntegralCache, NewPeriodicityClearIntegralCacheProcessor(l.svcCtx))

	// queue job , asynq support queue job
	// wait you fill..

	return mux
}
